<template>
	<view>
		<camera device-position="front" flash="off"  class="xzczxrtrt"></camera>
		<view class="kxzcertxer" :style="{left:sdfdsb+'%',top:sdfdsc+'%'}">
			<!-- {{sdfdsb}}
			<view class="">
				{{sdfdsc}}
			</view> -->
			<image class="w100 h100" v-if="sdfdsf"  src="https://duxinggj-1251133427.cos.ap-guangzhou.myqcloud.com/case/may/caishengmao.gif"></image>
		</view>
	</view>
</template>
<script lang="ts" setup>
	import { onLoad,onPageScroll,onShareAppMessage,onShow,onPullDownRefresh } from "@dcloudio/uni-app"
	import { ref } from "vue"
	import { hf, dxrequest, callBack } from "@/util/index.js"
	const src = ref()
	const takePhoto = () => {
		const ctx = uni.createCameraContext();
		const xzcdsferr = ctx.onCameraFrame((frame) => {
			console.log(frame)
			jiance(frame)
		})
		xzcdsferr.start()
	}
	onLoad(()=>{
		takePhoto()
	})
	const jzdxcfvds = ref()
	const sdfdsf = ref()

	const sdfdsa = ref()
	const sdfdsb = ref()
	const sdfdsc = ref()
	const sdfdsd = ref()
	const jiance = (imgbuffer) => {
		// var frameBuffer =
		const session = wx.createVKSession({
			track: {
				face: { mode: 2 } // mode: 1 - 使用摄像头；2 - 手动传入图像
			},

		})
		session.start(errno => {
			if (errno) {
				// 如果失败，将返回 errno
			} else {
				// 否则，返回null，表示成功
				session.detectFace({
					frameBuffer: imgbuffer.data, // 图片 ArrayBuffer 数据。人脸图像像素点数据，每四项表示一个像素点的 RGBA
					width: imgbuffer.width, // 图像宽度
					height: imgbuffer.height,
					scoreThreshold: 0.5, // 评分阈值
					sourceType: 1,
					modelMode: 1,
				})
			}
		})


		session.on('updateAnchors', anchors => {
			sdfdsf.value = true
			anchors.forEach(anchor => {
				sdfdsa.value = anchor.points
				let jxsdfx = parseFloat(anchor.origin.x*100)
				let jxsdfy = parseFloat(anchor.origin.y*100)
				if(jxsdfx<30){
					jxsdfx+=14
				}else{
					jxsdfx+=16
				}
				if(jxsdfy>50){
					jxsdfy = jxsdfy-16
				}else{
					jxsdfy = jxsdfy-12
				}
				sdfdsb.value = jxsdfx
				sdfdsc.value =  jxsdfy
				
				
				// sdfdsd.value = JSON.stringify(anchor.angle)

			})
		})


		session.on('removeAnchors', () => {
			console.log("人脸消失", "removeAnchors")
			sdfdsf.value =false
		})
	}
	onShareAppMessage(() => {
		return {
			title: '',
			path: '/pages/xiangji/index'
		}
	})
</script>

<style scoped>
.xzczxrtrt{
	position: fixed;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	z-index: 999;
}
.kxzcertxer{
	width: 400rpx;
	height: 400rpx;
	position: fixed;
	left: 200rpx;
	top: 200rpx;
	z-index: 9999;
}
</style>